<template>
  <a-drawer :open="visible" title="库存变化明细" @close="onClose">
    <template #closeIcon>
      <close @on-close="onClose" />
    </template>
    <a-card size="small" title="基本信息">
      <a-descriptions size="small" :column="3">
        <a-descriptions-item label="商品名称">{{ options.goods_name }}</a-descriptions-item>
        <a-descriptions-item label="品牌">{{ options.brand?.brand_name }}</a-descriptions-item>
        <a-descriptions-item label="分类">{{ options.cate?.cate_name }}</a-descriptions-item>
        <a-descriptions-item label="可售库存">{{ options.totalAvailableQuantities }}</a-descriptions-item>
        <a-descriptions-item label="实际库存">{{ options.totalWarehouseQuantities }}</a-descriptions-item>
        <a-descriptions-item label="货值金额">{{ options?.totalAgreeAmount }}</a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="smart-margin-top10" size="small" :tab-list="tabList" :active-tab-key="activeKey" @tabChange="(key) => (activeKey = key)">
      <template #customTab="{ tab }">
        <span class="ant-card-head-title" :style="compactModeClass">
          {{ tab }}
        </span>
      </template>
      <template v-if="activeKey === 'inventory'">
        <InventoryOrderTable :data="options" />
      </template>
    </a-card>
    <template #footer>
      <a-button style="margin-right: 8px" @click="onClose">取消</a-button>
    </template>
  </a-drawer>
</template>

<script setup lang="ts">
import InventoryOrderTable from './inventory-order-table.vue'
const compactModeClass = inject('compactModeClass')

const emit = defineEmits(['refresh', 'reload-list'])

// --------------------- Drawer 显示与隐藏 ---------------------
// 是否展示
const visible = ref(false)
// 详情
const options = ref(undefined)
// 详情tab
const activeKey = ref('inventory')
const tabList = [
  {
    key: 'inventory',
    tab: '变动明细'
  }
]

async function showDrawer(item, warehouse_id) {
  options.value = {
    ...item,
    warehouse_id
  }
  visible.value = true
}

const onClose = () => {
  visible.value = false
}

defineExpose({
  showDrawer
})
</script>
